/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ez2find.manager;

import com.ez2find.model.Area;
import com.ez2find.model.Location;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Owner
 */
@Stateless
public class LocationManagerBean implements LocationManagerLocal {
    
    @PersistenceContext
    private EntityManager em;
    
    public void create(Location location)throws Exception {
        em.persist(location);
    }
 
    public void update(Location location)throws Exception {
        em.merge(location);
    }
    
    public void delete(Location location)throws Exception {
        location=em.merge(location);
        em.remove(location);
    }
    
    public Location find(long id){
        return em.find(Location.class,id);
    }

    public List<Location> listAll(){
        Query query=em.createNamedQuery("listAllLocations");
        List<Location> result=query.getResultList();
        return result;
    }
 
    public List<Location> locationsArea(Area area){
        Query query=em.createNamedQuery("locationsArea");
        query.setParameter("area", area);
        List<Location> result=query.getResultList();
        return result;
    }
    
}
